// pages/driver/driver.js
var app = getApp();
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		dataLista: [],
		page:1,
		loading:false,
		valloading:false,
		next:false,
		scrolltop:0,
		timeId:0,
		keyword:'',
		agreement:false,
		InitCity:{
			popup:false,
			component:false,
			province:'',
			city:'',
			isprovince:1,
			iscity:1
		},
	},
	keywordChange(){
		clearTimeout(this.timeId) //清除定时器
		this.timeId=setTimeout(()=>{
			this.Getdata();
		},800)
	},
	
	cityPopupOpen(){
		this.setData({
			"InitCity.popup":true,
			"InitCity.component":true
		});
	},
	ChangeCityVal(val){
		var province = val.detail.province;
		var city = val.detail.city;
		this.cityPopupClose();
		if(province!=this.data.InitCity.province || city!=this.data.InitCity.city){
			this.setData({
				"InitCity.province":province,
				"InitCity.city":city
			});
			this.Getdata();
		}
		
	},
	cityPopupClose(){
		this.setData({
			"InitCity.popup":false
		});
	},
	cityPopupAfterLeave(){
		this.setData({
			"InitCity.component":false
		});
	},
	
	showlocation() {
		this.setData({
			isshowlocation: true
		});
	},
	godetail(event) {
		var id = event.currentTarget.dataset.id;
		if(parseInt(id)>0){
			wx.navigateTo({
				url: '../reportdetail/reportdetail?id='+id,
			});
		}else{
			wx.showToast({
				title: '数据错误，请稍后再试',
				icon: 'error',
				duration: 2000
			});
		}
		
	},
	agreementConfirm(){
		wx.navigateTo({
			url: '../reportedit/reportedit',
		});
	},
	agreementClose(){
		this.setData({
			agreement: false
		});
	},
	handlereportedit() {
		if(!app.globalData.hasUserInfo){
			app.handleLogin();
			return false;
		}
		this.setData({
			agreement: true
		});
		
	},
	Getdata(type) {
		var self = this;
		var pdata = this.data;
		var param = {};
		if(type=='scroll' && parseInt(pdata.page)>1){
			param['page'] = parseInt(pdata.page);
		}else{
			wx.showLoading({
				title: '加载中...',
				mask:true
			});
			this.setData({
				page:1,
				scrolltop:0,
				loading:true,
			});
		}
		if(pdata.keyword){
			param['keyword'] = pdata.keyword;
		}
		if(pdata.InitCity.province){
			param['province'] = pdata.InitCity.province+'省';
		}
		wx.request({
			url: 'https://www.grabinter.com/Prosecute/index',
			method: 'POST',
			header: {
				"Content-Type": 'application/x-www-form-urlencoded'
			},
			data:param,
			success: json => {
				if(type=='scroll'){
					var cont = this.data.dataLista.concat(json.data.data);
				}else{
					var cont = json.data.data;
					wx.hideLoading();
				}
				
				this.setData({
					dataLista: cont,
					page:json.data.next?json.data.page:self.data.page,
					next:json.data.next,
					valloading:false,
					loading:false
				})
			}
		});
	},
	LoadMore(){
		if(!this.data.next){
			return false;
		}
		if(this.data.valloading){
			return false
		}
		this.setData({
			valloading:true,
		});
		this.GetData('scroll')
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {

	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {
		this.Getdata();
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
